﻿//----------------------------------------------------------------------------------
// 脚本     ：GridHelper.js
//
// 用途     ：现用于Grid控件之CheckBox选择功能
//
// 创建人   ：席吉波
//
// 创建日期 ：2011-05-09
//----------------------------------------------------------------------------------
///<summery>
/// CheckBox 全选或者撤销全选
///<summery>
function CheckBoxAllClick(p_sourceDataList, p_GridClientStateID, p_value) {
    
    var el = document.getElementsByTagName('input');
    var len = el.length;    
    
    //全选 
    if ( p_value == true) {
        for (var i = 0; i < len; i++) {
            if ((el[i].type == "checkbox") && (el[i].name == "KevinXiCheckBoxItem")) {
                if (el[i].checked != true) {
                    el[i].click();
                }
            }
        }
    }
 
    //撤销全选
    if ( p_value == false) {
        for (var i = 0; i < len; i++) {
            if ((el[i].type == "checkbox") && (el[i].name == "KevinXiCheckBoxItem")) {
                if (el[i].checked == true) {
                    el[i].click();
                }
            }
        }
    }
}
//---------------------------------------------------分割线-----------------------------------------------------------
///<summery>
/// CheckBox 单项选择
///<summery>
function CheckBoxItemClick(p_sourceData, p_GridClientStateID, p_value) {
    var clientStateControl = $get(p_GridClientStateID);
    var clientState = Sys.Serialization.JavaScriptSerializer.deserialize(clientStateControl.value);
    var v_selecedDataList = clientState.SelectedDataFieldList;
    //alert(Sys.Serialization.JavaScriptSerializer.serialize(p_sourceData));
    //return;
    var obj = Sys.Serialization.JavaScriptSerializer.deserialize(p_sourceData);
    var contains = false;
    //选中
    if (p_value == true) {
        if (v_selecedDataList == null) {
            v_selecedDataList = new Array();
        }
        v_selecedDataList.push(obj);
    }
    //取消选中
    if (p_value == false) {
        for (var i = 0, k = 0; i < v_selecedDataList.length; i++) {
            if (v_selecedDataList[i] != obj) {
                v_selecedDataList[k++] = v_selecedDataList[i];
                contains = true;
            }
        }
        if (contains == true) {
            v_selecedDataList.length -= 1;
        }
    }
    //更新客户端状态
    clientState.SelectedDataFieldList = v_selecedDataList;
    clientStateControl.value = Sys.Serialization.JavaScriptSerializer.serialize(clientState);

}
//---------------------------------------------------分割线-----------------------------------------------------------
//展开时 创建一个新的Grid
function NewGrid(templateGridID, clientStateFieldID, holderID, servicePath, queryMethod, queryParaValues, subGridCssClassName, holderParentID) {
    try {
        var holder = $get(holderID);
        var holderParent = $get(holderParentID);
        if (holderParent.style.display === 'none') {
            if (holder.innerHTML === '') {
                var grid = $find(holderID);
                if (grid) {
                    grid.dispose();
                }
                    grid = $create(Kevin.Controls.Grid, {
                        "AutoGetData": false,
                        "clientStateField": $get(clientStateFieldID),
                        "gridCssClass": subGridCssClassName,
                        "queryMethod": queryMethod,
                        "servicePath": servicePath,
                        "QueryControlID": clientStateFieldID,
                        "QueryParameterValues": queryParaValues
                    }, null, null, $get(holderID));
                    
                grid._getData();
            }
            holderParent.style.display = '';
        }
        else {
            holderParent.style.display = 'none';
        }
    }
    catch (e) {
        alert("数据钻取失败："+e);
    }
}

function ExtendControlClicked(controlID,extendTitle,extendHiddenTitle)
{
    var control = $get(controlID);
    if (control) {
        if (control.className == "GridExtend") {
            //control = "折叠";
            control.className = "GridExtend-hidden";
            control.title = extendHiddenTitle;
        }
        else {
            //control.innerHTML = "展开";
            control.className = "GridExtend";
            control.title = extendTitle;
        }
    }
}
